package space.position;

import java.util.Objects;
import java.util.Random;

/**
 * 生成getter、setter
 * Alt键  + Insert键
 *
 *
 * 二维空间坐标点类
 * */
public class Point {
    private int x;      // x坐标
    private int y;      // y坐标

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 随机生成点
     * @param random        随机生成器
     * @param xBound        x坐标范围（0 ~ xBound）
     * @param xSkewing      x坐标偏移量
     * @param yBound        x坐标范围（0 ~ yBound）
     * @param ySkewing      y坐标偏移量
     * */
    public Point(Random random, int xBound, int xSkewing, int yBound, int ySkewing) {
        x = random.nextInt(xBound) + xSkewing;
        y = random.nextInt(yBound) + ySkewing;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    @Override
    public String toString() {
        return "(" + x + ", " + y +')';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Point)) return false;
        Point point = (Point) o;
        return x == point.x && y == point.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    /** 获取该点到坐标原点的距离 */
    public int getDistanceFromTheOrigin() {
        return (int)Math.sqrt(x * x + y * y);
    }
}
